<template>
    <div class="app-container">
        <div>
            <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="开发单号" prop="spNo">
        <el-input
          v-model="queryParams.spNo"
          placeholder="请输入开发单号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="开发日期" prop="spDate">
        <el-date-picker clearable
          v-model="queryParams.spDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择开发日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="交货日期" prop="deliDate">
        <el-date-picker clearable
          v-model="queryParams.deliDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择交货日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="客户ID" prop="custId">
        <el-input
          v-model="queryParams.custId"
          placeholder="请输入客户ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="款号" prop="khNo">
        <el-input
          v-model="queryParams.khNo"
          placeholder="请输入款号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="款号版本" prop="khVer">
        <el-input
          v-model="queryParams.khVer"
          placeholder="请输入款号版本"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="客款号" prop="custKhNo">
        <el-input
          v-model="queryParams.custKhNo"
          placeholder="请输入客款号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="样品分类" prop="mcId">
        <el-input
          v-model="queryParams.mcId"
          placeholder="请输入样品分类"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="系列" prop="series">
        <el-input
          v-model="queryParams.series"
          placeholder="请输入系列"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="样品描述" prop="describe">
        <el-input
          v-model="queryParams.describe"
          placeholder="请输入样品描述"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="设计师" prop="designer">
        <el-input
          v-model="queryParams.designer"
          placeholder="请输入设计师"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="出格人" prop="makePaper">
        <el-input
          v-model="queryParams.makePaper"
          placeholder="请输入出格人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="做版人" prop="makeSample">
        <el-input
          v-model="queryParams.makeSample"
          placeholder="请输入做版人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="业务员" prop="salesStaff">
        <el-input
          v-model="queryParams.salesStaff"
          placeholder="请输入业务员"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="图片" prop="imagePath">
        <el-input
          v-model="queryParams.imagePath"
          placeholder="请输入图片"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="创建日期" prop="createDate">
        <el-date-picker clearable
          v-model="queryParams.createDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择创建日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="创建人ID" prop="createStaffId">
        <el-input
          v-model="queryParams.createStaffId"
          placeholder="请输入创建人ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="创建人姓名" prop="createStaffName">
        <el-input
          v-model="queryParams.createStaffName"
          placeholder="请输入创建人姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="修改日期" prop="modifyDate">
        <el-date-picker clearable
          v-model="queryParams.modifyDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择修改日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="修改人ID" prop="modifyStaffId">
        <el-input
          v-model="queryParams.modifyStaffId"
          placeholder="请输入修改人ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="修改人姓名" prop="modifyStaffName">
        <el-input
          v-model="queryParams.modifyStaffName"
          placeholder="请输入修改人姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="审核状态" prop="pass">
        <el-input
          v-model="queryParams.pass"
          placeholder="请输入审核状态"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="审核日期" prop="passDate">
        <el-date-picker clearable
          v-model="queryParams.passDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择审核日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="审核人ID" prop="passStaffId">
        <el-input
          v-model="queryParams.passStaffId"
          placeholder="请输入审核人ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="审核人姓名" prop="passStaffName">
        <el-input
          v-model="queryParams.passStaffName"
          placeholder="请输入审核人姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
        </div>
    <el-tabs v-model="activeName" type="card" @tab-click="handleClick">
      <!-- 在目标 tab-pane 中嵌入子组件 -->
      <el-tab-pane label="样品明细" name="first">
        <el-table :data="samSampleSonList" :row-class-name="rowSamSampleSonIndex" @selection-change="handleSamSampleSonSelectionChange" ref="samSampleSon">
          <el-table-column type="selection" width="50" align="center" />
          <el-table-column label="序号" align="center" prop="index" width="50"/>
          <el-table-column label="颜色" prop="prodClName" width="150">
            <template slot-scope="scope">
              <el-input v-model="scope.row.prodClName" placeholder="请输入颜色" />
            </template>
          </el-table-column>
          <el-table-column label="数量" prop="num" width="150">
            <template slot-scope="scope">
              <el-input v-model="scope.row.num" placeholder="请输入数量" />
            </template>
          </el-table-column>
          <el-table-column label="实际做版数量" prop="factNum" width="150">
            <template slot-scope="scope">
              <el-input v-model="scope.row.factNum" placeholder="请输入实际做版数量" />
            </template>
          </el-table-column>
          <el-table-column label="寄版数量" prop="sendNum" width="150">
            <template slot-scope="scope">
              <el-input v-model="scope.row.sendNum" placeholder="请输入寄版数量" />
            </template>
          </el-table-column>
          <el-table-column label="做版用时" prop="makeTime" width="150">
            <template slot-scope="scope">
              <el-input v-model="scope.row.makeTime" placeholder="请输入做版用时" />
            </template>
          </el-table-column>
          <el-table-column label="报价单价" prop="quotePrice" width="150">
            <template slot-scope="scope">
              <el-input v-model="scope.row.quotePrice" placeholder="请输入报价单价" />
            </template>
          </el-table-column>
          <el-table-column label="收到客户资料日期" prop="recCustFileDate" width="240">
            <template slot-scope="scope">
              <el-date-picker clearable v-model="scope.row.recCustFileDate" type="date" value-format="yyyy-MM-dd" placeholder="请选择收到客户资料日期" />
            </template>
          </el-table-column>
          <el-table-column label="版房接单日期" prop="pdRecFileDate" width="240">
            <template slot-scope="scope">
              <el-date-picker clearable v-model="scope.row.pdRecFileDate" type="date" value-format="yyyy-MM-dd" placeholder="请选择版房接单日期" />
            </template>
          </el-table-column>
          <el-table-column label="版料备齐日期" prop="matReadyOkDate" width="240">
            <template slot-scope="scope">
              <el-date-picker clearable v-model="scope.row.matReadyOkDate" type="date" value-format="yyyy-MM-dd" placeholder="请选择版料备齐日期" />
            </template>
          </el-table-column>
          <el-table-column label="计划交货日期" prop="planDeliDate" width="240">
            <template slot-scope="scope">
              <el-date-picker clearable v-model="scope.row.planDeliDate" type="date" value-format="yyyy-MM-dd" placeholder="请选择计划交货日期" />
            </template>
          </el-table-column>
          <el-table-column label="实际交货日期" prop="factDeliDate" width="240">
            <template slot-scope="scope">
              <el-date-picker clearable v-model="scope.row.factDeliDate" type="date" value-format="yyyy-MM-dd" placeholder="请选择实际交货日期" />
            </template>
          </el-table-column>
          <el-table-column label="确认状态" prop="okStatus" width="150">
            <template slot-scope="scope">
              <el-select v-model="scope.row.okStatus" placeholder="请选择确认状态">
                <el-option label="请选择字典生成" value="" />
              </el-select>
            </template>
          </el-table-column>
          <el-table-column label="取消" prop="ynUndo" width="150">
            <template slot-scope="scope">
              <el-input v-model="scope.row.ynUndo" placeholder="请输入取消" />
            </template>
          </el-table-column>
          <el-table-column label="备注" prop="remark" width="150">
            <template slot-scope="scope">
              <el-input v-model="scope.row.remark" placeholder="请输入备注" />
            </template>
          </el-table-column>
          <el-table-column label="出格完成时间" prop="chugeFinishDate" width="240">
            <template slot-scope="scope">
              <el-date-picker clearable v-model="scope.row.chugeFinishDate" type="date" value-format="yyyy-MM-dd" placeholder="请选择出格完成时间" />
            </template>
          </el-table-column>
          <el-table-column label="打版完成时间" prop="patternFinishDate" width="240">
            <template slot-scope="scope">
              <el-date-picker clearable v-model="scope.row.patternFinishDate" type="date" value-format="yyyy-MM-dd" placeholder="请选择打版完成时间" />
            </template>
          </el-table-column>
          <el-table-column label="样品配色" prop="prodClName2" width="150">
            <template slot-scope="scope">
              <el-input v-model="scope.row.prodClName2" placeholder="请输入样品配色" />
            </template>
          </el-table-column>
          <el-table-column label="产品ID，用于版单自动生产产品用" prop="matId" width="150">
            <template slot-scope="scope">
              <el-input v-model="scope.row.matId" placeholder="请输入产品ID，用于版单自动生产产品用" />
            </template>
          </el-table-column>
          <el-table-column label="产品编号" prop="matNo" width="150">
            <template slot-scope="scope">
              <el-input v-model="scope.row.matNo" placeholder="请输入产品编号" />
            </template>
          </el-table-column>
          <el-table-column label="产品名称" prop="matName" width="150">
            <template slot-scope="scope">
              <el-input v-model="scope.row.matName" placeholder="请输入产品名称" />
            </template>
          </el-table-column>
          <el-table-column label="图片" prop="imagePath" width="150">
            <template slot-scope="scope">
              <el-input v-model="scope.row.imagePath" placeholder="请输入图片" />
            </template>
          </el-table-column>
          <el-table-column label="开发类型" prop="spType" width="150">
            <template slot-scope="scope">
              <el-select v-model="scope.row.spType" placeholder="请选择开发类型">
                <el-option label="请选择字典生成" value="" />
              </el-select>
            </template>
          </el-table-column>
          <el-table-column label="款号" prop="khNo" width="150">
            <template slot-scope="scope">
              <el-input v-model="scope.row.khNo" placeholder="请输入款号" />
            </template>
          </el-table-column>
          <el-table-column label="款号版本" prop="khVer" width="150">
            <template slot-scope="scope">
              <el-input v-model="scope.row.khVer" placeholder="请输入款号版本" />
            </template>
          </el-table-column>
          <el-table-column label="客款号" prop="custKhNo" width="150">
            <template slot-scope="scope">
              <el-input v-model="scope.row.custKhNo" placeholder="请输入客款号" />
            </template>
          </el-table-column>
          <el-table-column label="制造要求" prop="makeDemand" width="150">
            <template slot-scope="scope">
              <el-input v-model="scope.row.makeDemand" placeholder="请输入制造要求" />
            </template>
          </el-table-column>
          <el-table-column label="英文颜色" prop="engColor" width="150">
            <template slot-scope="scope">
              <el-input v-model="scope.row.engColor" placeholder="请输入英文颜色" />
            </template>
          </el-table-column>
          <el-table-column label="客户产品名称" prop="custMatName" width="150">
            <template slot-scope="scope">
              <el-input v-model="scope.row.custMatName" placeholder="请输入客户产品名称" />
            </template>
          </el-table-column>
          <el-table-column label="客户组别" prop="custGroup" width="150">
            <template slot-scope="scope">
              <el-input v-model="scope.row.custGroup" placeholder="请输入客户组别" />
            </template>
          </el-table-column>
          <el-table-column label="操作" width="120" align="center" fixed="right">
            <template slot-scope="scope">
            <el-button
              size="mini"
              type="text"
              icon="el-icon-edit"
              @click="handleUpdate(scope.row)"
             、
            >修改</el-button>
            <el-button
              size="mini"
              type="text"
              icon="el-icon-share"
              @click="handlePass(scope.row)"
            >{{ scope.row.pass == 1?'反审':'审核' }}</el-button>
            <el-button
              size="mini"
              type="text"
              icon="el-icon-delete"
              @click="handleDelete(scope.row)"
              、
            >删除</el-button>
          </template>
            </el-table-column>
        </el-table>
      </el-tab-pane>
      
      <el-tab-pane label="配置管理" name="second">配置管理</el-tab-pane>
      <el-tab-pane label="角色管理" name="third">角色管理</el-tab-pane>
      <el-tab-pane label="定时任务补偿" name="fourth">定时任务补偿</el-tab-pane>
    </el-tabs>
    </div>
  </template>
  
  <script>
  // 1. 导入子组件
  import sampleSon from './sampleSon.vue'; // 确认路径是否正确
  import sample from './sample.vue'
  
  export default {

    data() {
      return {
        activeName: 'first',
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 子表选中数据
      checkedSamSampleSon: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 样品开发单表格数据
      sampleList: [],
      // ${subTable.functionName}表格数据
      samSampleSonList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        spNo: null,
        spDate: null,
        deliDate: null,
        spType: null,
        custId: null,
        khNo: null,
        khVer: null,
        custKhNo: null,
        mcId: null,
        type: null,
        series: null,
        describe: null,
        designer: null,
        makePaper: null,
        makeSample: null,
        salesStaff: null,
        imagePath: null,
        createDate: null,
        createStaffId: null,
        createStaffName: null,
        modifyDate: null,
        modifyStaffId: null,
        modifyStaffName: null,
        pass: null,
        passDate: null,
        passStaffId: null,
        passStaffName: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    }
  },
  created() {
    this.getList()
  },
  methods: {
    /** 查询样品开发单列表 */
    getList() {
      this.loading = true
    //   listSample(this.queryParams).then(response => {
    //     this.sampleList = response.rows
    //     this.total = response.total
    //     this.loading = false
    //   })
    },
    // 取消按钮
    cancel() {
      this.open = false
      this.reset()
    },
    // 表单重置
    reset() {
      this.form = {
        spId: null,
        spNo: null,
        spDate: null,
        deliDate: null,
        spType: null,
        custId: null,
        khNo: null,
        khVer: null,
        custKhNo: null,
        mcId: null,
        type: null,
        series: null,
        describe: null,
        designer: null,
        makePaper: null,
        makeSample: null,
        salesStaff: null,
        remark: null,
        imagePath: null,
        createDate: null,
        createStaffId: null,
        createStaffName: null,
        modifyDate: null,
        modifyStaffId: null,
        modifyStaffName: null,
        pass: null,
        passDate: null,
        passStaffId: null,
        passStaffName: null
      }
      this.samSampleSonList = []
      this.resetForm("form")
    },
    /** 搜索按钮操作 */
    handleQuery() {
      
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm")
      this.handleQuery()
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.spId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset()
      this.open = true
      this.title = "添加样品开发单"
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset()
      const spId = row.spId || this.ids
      getSample(spId).then(response => {
        this.form = response.data
        this.samSampleSonList = response.data.samSampleSonList
        this.open = true
        this.title = "修改样品开发单"
      })
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          this.form.samSampleSonList = this.samSampleSonList
          if (this.form.spId != null) {
            updateSample(this.form).then(response => {
              this.$modal.msgSuccess("修改成功")
              this.open = false
              this.getList()
            })
          } else {
            addSample(this.form).then(response => {
              this.$modal.msgSuccess("新增成功")
              this.open = false
              this.getList()
            })
          }
        }
      })
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const spIds = row.spId || this.ids
      this.$modal.confirm('是否确认删除样品开发单编号为"' + spIds + '"的数据项？').then(function() {
        return delSample(spIds)
      }).then(() => {
        this.getList()
        this.$modal.msgSuccess("删除成功")
      }).catch(() => {})
    },
	/** ${subTable.functionName}序号 */
    rowSamSampleSonIndex({ row, rowIndex }) {
      row.index = rowIndex + 1
    },
    /** ${subTable.functionName}添加按钮操作 */
    handleAddSamSampleSon() {
      let obj = {}
      obj.prodClName = ""
      obj.num = ""
      obj.factNum = ""
      obj.sendNum = ""
      obj.makeTime = ""
      obj.quotePrice = ""
      obj.recCustFileDate = ""
      obj.pdRecFileDate = ""
      obj.matReadyOkDate = ""
      obj.planDeliDate = ""
      obj.factDeliDate = ""
      obj.okStatus = ""
      obj.ynUndo = ""
      obj.remark = ""
      obj.chugeFinishDate = ""
      obj.patternFinishDate = ""
      obj.prodClName2 = ""
      obj.matId = ""
      obj.matNo = ""
      obj.matName = ""
      obj.imagePath = ""
      obj.spType = ""
      obj.khNo = ""
      obj.khVer = ""
      obj.custKhNo = ""
      obj.makeDemand = ""
      obj.engColor = ""
      obj.custMatName = ""
      obj.custGroup = ""
      this.samSampleSonList.push(obj)
    },
    /** ${subTable.functionName}删除按钮操作 */
    handleDeleteSamSampleSon() {
      if (this.checkedSamSampleSon.length == 0) {
        this.$modal.msgError("请先选择要删除的${subTable.functionName}数据")
      } else {
        const samSampleSonList = this.samSampleSonList
        const checkedSamSampleSon = this.checkedSamSampleSon
        this.samSampleSonList = samSampleSonList.filter(function(item) {
          return checkedSamSampleSon.indexOf(item.index) == -1
        })
      }
    },
    /** 复选框选中数据 */
    handleSamSampleSonSelectionChange(selection) {
      this.checkedSamSampleSon = selection.map(item => item.index)
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/sample/export', {
        ...this.queryParams
      }, `sample_${new Date().getTime()}.xlsx`)
    }
  }
}
  </script>
